<template>
  <div class="action-sheet" @click="hideActionSheet">
    <ul class="action-sheet-list" :class="{ show: isShowList }">
      <li
        v-for="(item, index) in $store.state.actionSheetConfig.list"
        :key="index"
        @click="clickHandler(index)"
      >
        {{ item }}
      </li>
      <li>取消</li>
    </ul>
  </div>
</template>

<script setup>
import { useStore } from "vuex";
import { onMounted, ref } from "vue";
const store = useStore();
// 控制列表的异步弹出
let isShowList = ref(false);

// 关闭组件
function hideActionSheet() {
  store.commit("hideActionSheet");
}
// 处理每一个li的回调事件
function clickHandler(index) {
  if (typeof store.state.actionSheetConfig.successCallBack == "function") {
    store.state.actionSheetConfig.successCallBack(index);
  }
}

onMounted(() => {
  setTimeout(() => {
    isShowList.value = true;
  }, 100);
});
</script>

<style lang="scss" scoped>
.action-sheet {
  background-color: rgba(0, 0, 0, 0.8);
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  .action-sheet-list {
    background-color: gray;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    transform: translateY(100%);
    transition: all 300ms linear;
    &.show {
      transform: translateY(0);
    }
    li {
      height: 35px;
      @include flexbox(row, center, center);
      background-color: white;
      border-bottom: 1px solid lightgray;
      user-select: none;
      &:last-child {
        margin-top: 5px;
      }
    }
  }
}
</style>